# 多阶段构建：前端构建 + 后端运行

# Stage 1: Build frontend
FROM node:18-alpine AS client-builder
WORKDIR /app/client
COPY client/package*.json ./
RUN npm ci --only=production
COPY client/ ./
RUN npm run build

# Stage 2: Backend runtime
FROM node:18-alpine
WORKDIR /app

# 安装后端依赖
COPY package*.json ./
COPY server/package*.json ./server/
RUN npm ci --only=production

# 复制后端代码
COPY server/ ./server/
COPY .env.example .env

# 复制前端构建产物（如需静态托管可用 nginx，此处示例直接放 app）
COPY --from=client-builder /app/client/dist ./client/dist

# 可选：复制图标资源
COPY 小图标/ ./小图标/

EXPOSE 4000

CMD ["node", "server/index.js"]
